package TeachLesson.CourseWork;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

@WebServlet(name = "deleteCourseWorksServlet")
public class deleteCourseWorksServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       int id=Integer.parseInt(request.getParameter("id"));
        //获取文件路径
        String filePath=request.getParameter("filePath");
        String workerNo=request.getParameter("workerNo");
        String courseNo=request.getParameter("courseNo");
       CourseWorkDao courseWorkDao=new CourseWorkDao();
       courseWorkDao.deleteCourseWork(id);
        File file=new File(filePath);
        if(file.exists()){
            //如果文件存在删除该文件
            file.delete();
        }

        response.sendRedirect("/Teachers/courseWorkMangement.jsp?workerNo="+workerNo+"&courseNo="+courseNo);
    }
}
